from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates

import uvicorn

app = FastAPI()
templates = Jinja2Templates(directory="templates")


@app.get("/")
async def index(request: Request):
    user = "Json"
    age = 18
    books = [
        "金瓶梅",
        "聊斋",
        "剪灯新话",
        "国色天香"
    ]
    info = {"name": "Json", "age": 18, "gender": "male"}
    return templates.TemplateResponse("index.html", {
        "request": request,
        "user": user,
        "age": age,
        "books": books,
        "info": info
    })


if __name__ == "__main__":
    uvicorn.run(app, host="127.0.0.1", port=8000)
